{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": [],
      "authorship_tag": "ABX9TyNuWIELWWDtoNBAYOHZfXRi",
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/liudf0716/xfrpc/blob/master/colab_xfrpc.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "ErrkZjxXvVNe"
      },
      "outputs": [],
      "source": [
        "!git clone https://github.com/liudf0716/xfrpc.git\n",
        "! cd xfrpc/ && mkdir build && cd build && cmake .. && make && cp xfrpc /usr/bin/"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "! pip install configparser\n",
        "\n",
        "import configparser\n",
        "import sys\n",
        "\n",
        "server_addr = \"colab.xfrpc.xyz\" #@param {type:\"string\"}\n",
        "token = \"l00JJ6ea302lT\" #@param {type:\"string\"}\n",
        "server_port = 8443 #@param {type:\"integer\"}\n",
        "remote_port = 6003 #@param {type:\"integer\"}\n",
        "plugin_user = \"xfrpc\" #@param {type:\"string\"}\n",
        "plugin_pwd = \"123456\" #@param {type:\"string\"}\n",
        "\n",
        "def get_input(prompt):\n",
        "    \"\"\"Gets input from the user.\"\"\"\n",
        "    return input(prompt)\n",
        "\n",
        "def generate_ini(server_addr, server_port, token, remote_port, user, pwd):\n",
        "    \"\"\"Generates an INI file.\"\"\"\n",
        "    config = configparser.ConfigParser()\n",
        "\n",
        "    config[\"common\"] = {\n",
        "        \"server_addr\": server_addr,\n",
        "        \"server_port\": server_port,\n",
        "        \"token\": token,\n",
        "    }\n",
        "\n",
        "    config[\"telnetd\"] = {\n",
        "        \"type\": \"tcp\",\n",
        "        \"remote_port\": remote_port,\n",
        "        \"plugin\": \"telnetd\",\n",
        "        \"plugin_user\": user,\n",
        "        \"plugin_pwd\": pwd,\n",
        "    }\n",
        "\n",
        "    with open(\"my.ini\", \"w\") as f:\n",
        "        config.write(f)\n",
        "\n",
        "    print(\"Ini file generated successfully!\")\n",
        "\n",
        "if __name__ == \"__main__\":\n",
        "    generate_ini(server_addr, server_port, token, remote_port, plugin_user, plugin_pwd)\n",
        "\n"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "V7n8azihcBUl",
        "outputId": "b7d475f9-49af-4546-8381-b96a577258cb"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Requirement already satisfied: configparser in /usr/local/lib/python3.10/dist-packages (6.0.0)\n",
            "Ini file generated successfully!\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "! xfrpc -c my.ini -f -d 6"
      ],
      "metadata": {
        "id": "KFLJaznZvrLG"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}
